package tdh.xt.entity.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.ToString;

import java.util.List;

/*
* @Package tdh.xt.entity.vo
* @Description 分页信息类
* @Author RicarAN
* @Date 2021/6/15 16:37
* @Copyright (c) 2021,南京通达海科技股份有限公司 All Rights Reserved.
* @Version 1.0
* Modification History:  
* Date                  Author      Version     Description  
* ------------------------------------------------------------------  
* 2021/6/15 16:37       RicarAN      1.0        分页信息类
*
*/
@Getter
@ToString
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Page<T> {
    private Integer pageSize;
    private Integer currentPage;
    private Integer totalPage;
    private Integer totalCount;
    private Integer offset;
    private Integer limit;
    private Integer previous;
    private Integer next;
    private List<T> data;

    /*
     * @description 构造函数，必须提供当前页和分页大小，会自动设置其它值
     * @param start 当前页
	 * @param pageSize    分页大小
     * @author RicarAN
     * @version 1.0
     * @date 2021/6/15 16:38
     */
    public Page(Integer start, Integer pageSize) {
        this.offset = Math.max(start - 1, 0);
        this.pageSize = Math.max(pageSize, 0);
        this.limit = this.pageSize <= 0 ? 50 : this.pageSize;
        this.currentPage = start / pageSize + 1;
        this.previous = this.currentPage - 1;
        this.next = this.currentPage + 1;
    }

    /*
     * @description 设置数据总条数，会自动根据分页大小设置总页码
     * @param totalCount 数据总条数
     * @author RicarAN
     * @version 1.0
     * @date 2021/6/15 16:39
     */
    public void setTotalCount(Integer totalCount) {
        this.totalCount = Math.max(totalCount, 0);
        int temp = this.totalCount / pageSize;
        this.totalPage = this.totalCount % pageSize == 0 ? temp : temp + 1;
    }

    /*
     * @description 设置分页数据
     * @param data 数据
     * @author RicarAN
     * @version 1.0
     * @date 2021/6/15 16:40
     */
    public void setData(List<T> data) {
        this.data = data;
    }
}
